﻿package mortal.game.scene3D.layer3D.utils
{
    import Message.Public.*;
    import com.gengine.debug.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import mortal.game.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.player.item.*;

    public class JumpUtil extends EntityLayerUtil
    {
        private var _map:JumpDictionary;

        public function JumpUtil(param1:PlayerLayer)
        {
            this._map = new JumpDictionary();
            super(param1);
            return;
        }// end function

        public function getJump(param1:int, param2:int) : JumpPlayer
        {
            return this._map.getJump(param1, param2);
        }// end function

        public function addJump(param1:SPoint) : JumpPlayer
        {
            var _loc_2:* = GlobalStaticResUrl.Jump;
            var _loc_3:* = this._map.getJump(param1.x, param1.y) as JumpPlayer;
            if (_loc_3 == null)
            {
                _loc_3 = FrObjectPool.getObject(JumpPlayer, this) as JumpPlayer;
                this._map.addJump(param1.x, param1.y, _loc_3);
            }
            _loc_3.updatePoint(param1);
            Log.debug("增加跳跃点:", param1.x, param1.y);
            layer.addChild(_loc_3);
            return _loc_3;
        }// end function

        public function removeJump(param1:int, param2:int) : void
        {
            var _loc_3:* = this._map.removeJump(param1, param2);
            if (_loc_3)
            {
                _loc_3.dispose();
            }
            return;
        }// end function

        public function addToStage(param1:JumpPlayer) : void
        {
            layer.addChild(param1);
            return;
        }// end function

        override public function removeAll() : void
        {
            this._map.removeAll();
            return;
        }// end function

        override public function updateEntity() : void
        {
            var _loc_2:JumpPlayer = null;
            var _loc_3:Point = null;
            var _loc_4:SPoint = null;
            if (!Game.sceneInfo)
            {
                return;
            }
            var _loc_1:* = Game.sceneInfo.jumpPoints;
            if (_loc_1.length < 1)
            {
                return;
            }
            for each (_loc_4 in _loc_1)
            {
                
                if (SceneRange.isInEffectRange(_loc_4.x, _loc_4.y))
                {
                    _loc_2 = this.getJump(_loc_4.x, _loc_4.y);
                    if (_loc_2 == null)
                    {
                        _loc_2 = this.addJump(_loc_4);
                    }
                    else if (_loc_2.parent == null)
                    {
                        this.addToStage(_loc_2);
                    }
                    continue;
                }
                this.removeJump(_loc_4.x, _loc_4.y);
            }
            return;
        }// end function

    }
}
